package ifmo.itip.applesgame;

import java.util.Random;
import java.util.concurrent.CountDownLatch;

public class Gamer extends Thread
{
	CountDownLatch cl;
	int id,myApple;
	Dispatcher d;
	public int x=0,y=0;
	public Gamer(Dispatcher d,int id)
	{
		this.id = id;
		this.d = d;
		//System.out.println(id);
	}
	public void eat()
	{
		System.out.println("Игрок "+this.id+" съел яблоко");
		this.myApple++;
		d.countApples--;
	}
	@Override
	public void run()
	{
		while(d.countApples!=d.countApplesEat)
		{
			Random rand = new Random();
			int hod = rand.nextInt(4);
			try {
				//sleep(1000);
					d.hod(this,hod);
			} catch (InterruptedException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		
	}

}
